<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp" %>
<%@ taglib prefix ="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
	<head>
		<%@ include file="/common/common-css.jsp" %>
		<style>
		#jquery-table td,#jquery-table td a{word-wrap: break-word;word-break: break-word; white-space: nowrap;}
		.load_bg{background:#000;opacity:0.1;left:0px;top:0px;position:fixed;height:100%;width:100%;overflow:hidden;z-index:10000;}
		.load_img{left:50%;top:180px;position:fixed;height:50px;overflow:hidden;z-index:20000;}
		</style>
	</head>
<body  class="no-skin">
<div  class="load_bg" style="display:none;" ></div>
<img src="http://img.xmiles.cn/commentloading.gif" class="load_img" style="display:none"/>
<div class="page-content">
<div id="test"></div>
	<form id="queryForm" >
	<div class="page-content-area">
		<div class="row">
				<div class="col-sm-12">
					<div class="widget-box" style="border:0px solid #ccc; border-top:none;border-bottom:none;">
						<div class="widget-header widget-header-blue widget-header-flat">
							<h4 class="widget-title">选择条件进行查询</h4>
	
							<div class="widget-toolbar">
								<a href="#" data-action="collapse">
									<i class="ace-icon fa fa-chevron-up"></i>
								</a>
							</div>
						</div>
	
						<div class=" widget-body">
								<div class="widget-main clearfix" >
									
									<div class="form-group col-xs-12 col-sm-3 col-md-3 col-lg-3">
										<label class="col-sm-4 control-label" for="activity" style="text-align:right;">活动名:</label>
										<div class="col-sm-8">
											<input type="text" class="form-control" name="activity" id="activity">
										</div>
									</div>
									
									<div class="form-group col-xs-12 col-sm-3 col-md-3 col-lg-3">
										<label class="col-sm-4 control-label" for="memo" style="text-align:right;">备注:</label>
										<div class="col-sm-8">
											<input type="text" class="form-control" name="memo" id="memo">
										</div>
									</div>

									<div class="form-group col-xs-12 col-sm-3 col-md-3 col-lg-3">
										<label class="col-sm-4 control-label" for="memo" style="text-align:right;">短链:</label>
										<div class="col-sm-8">
											<input type="text" class="form-control" name="shortLink" id="shortLink">
										</div>
									</div>

								</div><!-- /.widget-main -->
						</div><!-- /.widget-body -->
					</div><!-- /.widget-box -->
				</div><!-- /.col-sm-12 -->
				<div class="col-md-12 center">
				<div class="clearfix form-actions">
				
					<button class="btn btn-purple  no-border" type="button" name="btn-query" onclick="query_any()" id="btn-query">
						<i class="ace-icon fa fa-search icon-on-right bigger-110"></i>
						查询
					</button>
					&nbsp;&nbsp;&nbsp;
					<button class="btn btn-grey  no-border" type="button" name="btn-add" onclick="addshortlink()">
						<i class="ace-icon fa fa-undo icon-on-right bigger-110"></i>
						新建
					</button>
					&nbsp;&nbsp;&nbsp;
					<c:if test="${paramsMap.userId eq 'wuxiuxiu2017'}">
						<button class="btn btn-grey  no-border" type="button" name="btn-update-redirectLink" onclick="showUpdateRedirectLinkDialog()">
							<i class="ace-icon fa fa-undo icon-on-right bigger-110"></i>
							修改重定向链接
						</button>
					</c:if>

				  </div>
		   </div>
		</div><!-- /.row -->

		<div class="row">
			<div class="col-xs-12">
				<table id="jquery-table" class="table table-striped table-bordered table-hover">
				</table>
			</div><!-- /.col -->
		</div><!-- /.row -->
			
	</div><!-- /.page-content-area -->
	</form>
</div><!-- /.page-content -->

<%@ include file="/common/common-js.jsp" %>
<script type="text/javascript" src="${ctx}/js/call_func.js"></script>
<!-- inline scripts related to this page -->
<script type="text/javascript">

var channelId;

//接受URL参数，进行文档写入
function getQueryString(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
		var r = window.location.search.substr(1).match(reg);
	if (r != null) return decodeURI(r[2]); return null;
}

function addshortlink() {
  	openDialogWithRand("/spread/addshortlink.action",700,500,"添加短链接",function (data){});
};

function showUpdateRedirectLinkDialog() {
    openDialogWithRand("/spread/showUpdateRedirectLinkDialog.action",750,300,"修改重定向链接",function (data){});
}

		
//【查询】按钮Click事件
function query_any(){
	
	if(jqTable != null){
		jqTable.fnDraw();
		
	}else{
		loaddata();
	}
};


function openDialogWithRand(url,width,height,title,close){
	$(document).ExtDialog({
		url : ctx + url,
		width : width,
		height : height,
		title : title,
		close: close
	});
}
function getComfirm(id){
    if(confirm("是否确认修改")){
        updateIsUsed(id);
	}
}
function updateIsUsed(id) {
	$.ajax({
		type:"POST",
		url:ctx+"/spread/updateIsUsed.action?id="+id,
		async:false,
		success:function(data){
			query_any()
		}
	})
}
/* $(document).ready(function(){
	query_any();
}); */

var jqTable = null;
var loaddata = null;

loaddata = function(){
	jQuery(function($) {
		
		jqTable = $('#jquery-table').dataTable({
		    //数据列控制（包括对应返回JSON属性名称，对应表头列索引位置、数据转换封装等）
		    "columnDefs": [
		    	{
		    	 	  "title":"时间",
		    	 	  "name":"ctime",
		    	 	  "data": "ctime",
					  "class": "center",
		    	  	  "targets": [0] ,
		    	  	  "width": "300px",
		    	  	  "bSortable": false
		    	}
		    	,
		    	{
		    	 	  "title":"活动名",
		    	 	  "name":"activity",
		    	 	  "data": "activity",
					  "class": "center",
		    	  	  "targets": [1] ,
		    	  	  "bSortable": false,
		    	  	  "width": "300px"
		    	},
		    	{
		    	 	  "title":"备注",
		    	 	  "name":"memo",
		    	 	  "data": "memo",
					  "class": "center",
		    	  	  "targets": [2] ,
		    	  	  "bSortable": false,
		    	  	  "width": "300px"
		    	},
                {
                    "title":"链接是否可用",
                    "name":"isused_link",
                    "data":function (value, type, row) {
                            if(value.isused_link==0)
                                return "否";
                            else
                                return "是";
                        },
                    "class": "center",
                    "targets": [3] ,
                    "bSortable": false,
                    "width": "300px",
                    "render": function(value, type, row) {
                        var tep ="<a target='_blank' onclick='getComfirm("+ row.id +")'/>" + value + "</a>";
                        return tep;
                    }
                },
                {
                    "title":"作用环境",
                    "name":"environment",
                    "class": "left",
                    "data": function (value, type, row) {
                        if(value.environment == 1){
                            return "app内部";
						}else if(value.environment == 0){
                            return "app外部";
						}else{
                            return value.environment;
						}
                    },
                    "targets": [4] ,
                    "bSortable": false,
                    "width": "400px"
                },
		    	{
		    	 	  "title":"短连接",
		    	 	  "name":"short_link",
					  "class": "left",
		    	 	  "data": "short_link",
		    	  	  "targets": [5] ,
		    	  	  "bSortable": false,
		    	  	  "width": "400px",
		    	  	  "render": function(value, type, row) { 
		    	  	  		return '<a target="_blank" href="' + value + '">' + value + '</a>'
		    	  	  }
		    	},
		    	{
		    		  "title":"url",
		    		  "name":"url",
					  "class": "left",
		    		  "data": "url",
		    	  	  "targets": [6],
		    	  	  "bSortable": false,
		    	  	  "width": "400px",
		    	  	  "render": function(value, type, row) { 
		    	  	  		return '<a target="_blank" href="' + value + '">' + value + '</a>'
		    	  	  }
		    	},
		    	{
		    		  "title":"类型",
		    		  "name":"link_type",
					  "class": "left",
		    		  "data": "link_type",
		    	  	  "targets": [7],
		    	  	  "bSortable": false,
		    	  	  "width": "100px",
		    	},
		    	{
		    		  "title":"单价",
		    		  "name":"unit_price",
					  "class": "left",
		    		  "data": "unit_price",
		    	  	  "targets": [8],
		    	  	  "bSortable": false,
		    	  	  "width": "100px",
		    	}
		  	],
			"sAjaxSource": ctx+"/spread/queryShortLink.action",//数据源URL
			"fnServerData": function ( sSource, aoData, fnCallback ) {//从服务器请求数据
		   			var data = $('#queryForm').serializeObject();
					data.aoData = JSON.stringify(aoData);
					$.ajax({
						"type": "POST",
						"dataType": 'json',
						"url": sSource,
						"data":data,
						"beforeSend": function(){
							$(".load_bg,.load_img").show();
						},
						"success": function(resp){	
                            console.log(resp);					
							fnCallback(resp);
							initListPage();
							var allNum = 0;
							$('.count').each(function(){
								var num = $(this).text();
								num = +num;
								allNum = allNum + num;
							});
						},
						"error": function(XMLHttpRequest, textStatus, errorThrown) {
                            alert(textStatus);
						},
						"complete": function(){
							$(".load_bg,.load_img").hide();
						}
				});
			},
			
			"sScrollXInner": "100%",
			"sScrollY": "100%",//如果不设置，IE会有问题
			"aLengthMenu": [50, 100, 200], 
		    "aaSorting": [[2,"desc"]] //初始化加载，默认按第几列排序、排序方式（列从0开始计算）
		});
	});
};


</script>
		
</body>
</html>